package com.berwin.caper.view.components;

import com.berwin.caper.entity.Tag;

import javax.swing.*;
import javax.swing.filechooser.FileSystemView;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;

public class ItemTagView extends JPanel {

    public interface ItemTagClickedListener {
        void onItemTagClicked(ItemTagView itemTagView);
    }

    private Tag tag;
    private JLabel lblIcon;
    private JLabel lblName;
    private ItemTagClickedListener listener;


    public ItemTagView(Tag tag, ItemTagClickedListener listener) {
        this.tag = tag;
        this.listener = listener;

        this.setBackground(Color.WHITE);
        this.setLayout(new FlowLayout(FlowLayout.LEFT));

        this.lblIcon = new JLabel(FileSystemView.getFileSystemView().getSystemIcon(new File(this.tag.getPath())));
        this.add(lblIcon);

        this.lblName = new JLabel(this.tag.getName());
        Font font = new Font(this.lblName.getFont().getName(), Font.PLAIN, 10);
        this.lblName.setFont(font);
        this.add(lblName);

        this.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                listener.onItemTagClicked(ItemTagView.this);
            }
        });
    }

    public Tag getTag() {
        return tag;
    }

    public void setTag(Tag tag) {
        this.tag = tag;
    }

    public JLabel getLblIcon() {
        return lblIcon;
    }

    public void setLblIcon(JLabel lblIcon) {
        this.lblIcon = lblIcon;
    }

    public JLabel getLblName() {
        return lblName;
    }

    public void setLblName(JLabel lblName) {
        this.lblName = lblName;
    }

    public ItemTagClickedListener getListener() {
        return listener;
    }

    public void setListener(ItemTagClickedListener listener) {
        this.listener = listener;
    }
}
